package com.example.antdback.entity.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author ljg
 * description
 * @since 2021/8/29 11:42 上午
 **/
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -4756446292218165674L;

    private boolean success;
    private String code;
    private String msg;
    private T data;

    public static Result<Void> SUCCESS = success(null);

    private static <T> Result<T> create(boolean success, String code, String msg, T t) {
        return new Result<>(success, code, msg, t);
    }

    public static <T> Result<T> success(String msg, T t) {
        return create(true, "0", msg, t);
    }

    public static <T> Result<T> success(T t) {
        return create(true, "0", "成功", t);
    }

    public static <T> Result<T> fail(String code, String msg, T t) {
        return create(false, code, msg, t);
    }

    public static <T> Result<T> fail(String code, String msg) {
        return create(false, code, msg, null);
    }

    public static <T> Result<T> fail(String msg) {
        return create(false, "-1", msg, null);
    }

}
